<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: campaigns.php 23 2013-09-21 11:53:34Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 23 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:53:34 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */


require ('includes/application_top.php');

  require(DIR_WS_CLASSES.'currencies.php');
  $currencies = new currencies();

switch ($_GET['action']) {
	case 'insert' :
	case 'save' :
		$campaigns_id = ($_GET['cID']);
		$campaigns_name = ($_POST['campaigns_name']);
		$campaigns_refID = ($_POST['campaigns_refID']);
		$sql_data_array = array ('campaigns_name' => $campaigns_name, 'campaigns_refID' => $campaigns_refID);

		if ($_GET['action'] == 'insert') {
			$insert_sql_data = array ('date_added' => 'now()');
			$sql_data_array = array_merge($sql_data_array, $insert_sql_data);
			$db->db_perform(TABLE_CAMPAIGNS, $sql_data_array);
			$campaigns_id = $db->db_insert_id();
		}
		elseif ($_GET['action'] == 'save') {
			$update_sql_data = array ('last_modified' => 'now()');
			$sql_data_array = array_merge($sql_data_array, $update_sql_data);
			$db->db_perform(TABLE_CAMPAIGNS, $sql_data_array, 'update', "campaigns_id = ".$db->db_prepare($campaigns_id)."");
		}

		redirect(href_link(FILENAME_CAMPAIGNS, 'cID='.$campaigns_id.(isset($_GET['page']) ? '&page='.$_GET['page']:'')));
		break;

	case 'deleteconfirm' :

		$campaigns_id = ($_GET['cID']);

		$db->db_query("DELETE FROM ".TABLE_CAMPAIGNS." WHERE campaigns_id = ".$db->db_prepare($campaigns_id)."");
		$db->db_query("DELETE FROM ".TABLE_CAMPAIGNS_IP." WHERE campaign = ".$db->db_prepare($campaigns_id)."");

		if ($_POST['delete_refferers'] == 'on') {

			$db->db_query("UPDATE ".TABLE_ORDERS." set refferers_id = '' WHERE refferers_id = ".$db->db_prepare($campaigns_id)."");
			$db->db_query("UPDATE ".TABLE_CUSTOMERS." set refferers_id = '' WHERE refferers_id = ".$db->db_prepare($campaigns_id)."");
		}

		redirect(href_link(FILENAME_CAMPAIGNS, (isset($_GET['page']) ? 'page='.$_GET['page']:'')));
		break;
}
require(DIR_WS_INCLUDES.'metatag.php'); ?>
</head>
<body>
<?php require(DIR_WS_INCLUDES.'header.php'); ?>
<div id="wrapper">
<table class="outerTable" cellspacing="0" cellpadding="0">
  <tr>
    <td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
		<?php require(DIR_WS_INCLUDES.'column_left.php'); ?>
	</td>
    <td class="boxCenter" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td width="100%">
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
          		<tr>
            		<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
          		</tr>
        	</table>
		</td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CAMPAIGNS; ?></td>
                <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_ACTION; ?>&nbsp;</td>
              </tr>
				<?php

				$sql = "SELECT * from ".TABLE_CAMPAIGNS." ORDER BY campaigns_name";
				$query = page_break_create($_POST['per_site'], $_GET['page'], $sql, 'price_change.php');
				$campaigns = $query['query'];
				while (!$campaigns->EOF) {
					if (((!$_GET['cID']) || (@ $_GET['cID'] == $campaigns->fields['campaigns_id'])) && (!$cInfo) && (substr($_GET['action'], 0, 3) != 'new')) {
						$cInfo = new objectInfo($campaigns->fields);
					}

					if ((is_object($cInfo)) && ($campaigns->fields['campaigns_id'] == $cInfo->campaigns_id)) {
						echo '              <tr class="dataTableRowSelected" onmouseover="this.style.cursor=\'hand\'" onclick="document.location.href=\''.href_link(FILENAME_CAMPAIGNS, 'page='.$_GET['page'].'&cID='.$campaigns->fields['campaigns_id'].'&action=edit').'\'">'."\n";
					} else {
						echo '              <tr class="dataTableRow" onmouseover="this.className=\'dataTableRowOver\';this.style.cursor=\'hand\'" onmouseout="this.className=\'dataTableRow\'" onclick="document.location.href=\''.href_link(FILENAME_CAMPAIGNS, 'page='.$_GET['page'].'&cID='.$campaigns->fields['campaigns_id']).'\'">'."\n";
					}
				?>
				                <td class="dataTableContent"><?php echo $campaigns->fields['campaigns_name']; ?></td>
				                <td class="dataTableContent" align="right"><?php if ( (is_object($cInfo)) && ($campaigns->fields['campaigns_id'] == $cInfo->campaigns_id) ) { echo image(DIR_WS_IMAGES.'icon_arrow_right.gif'); } else { echo '<a href="'.href_link(FILENAME_CAMPAIGNS, 'page='.$_GET['page'].'&cID='.$campaigns->fields['campaigns_id']).'">'.image(DIR_WS_IMAGES.'icon_info.gif', IMAGE_ICON_INFO).'</a>'; } ?>&nbsp;</td>
				<?php
					echo '</tr>';
					$campaigns->MoveNext();
				}
				?>
              <tr>
                <td colspan="2"><table border="0" width="100%" cellspacing="0" cellpadding="2">
                 <tr class="page_break">
					<td class="smallText" valign="top" width="33.3%"><?php echo 'Angezeigt werden '.$query['from'].' bis '.$query['to'].' (von insgesamt '.$query['total'].' Kampagnen)'; ?></td>
					<td class="smallText" align="center" width="33.3%"></td>
					<td class="smallText" align="right" width="33.3%">
						Kampagnen pro Seite: <?php echo $query['page_break']->perSiteDropdown($_GET['page']); ?>
					</td>
				</tr>
				<tr><td align="center" colspan="3"><?php echo '<br />'.$query['links']; ?></td></tr>
                </table></td>
              </tr>
				<?php

				if ($_GET['action'] != 'new') {
				?>
              <tr>
                <td align="right" colspan="2" class="smallText"><?php echo button_link(BUTTON_INSERT, href_link(FILENAME_CAMPAIGNS, 'page='.$_GET['page'].'&cID='.$cInfo->campaigns_id.'&action=new')); ?></td>
              </tr>
				<?php

				}
				?>
            </table></td>
				<?php

				$heading = array ();
				$contents = array ();
				switch ($_GET['action']) {
					case 'new' :
						$heading[] = array ('text' => '<b>'.TEXT_HEADING_NEW_CAMPAIGN.'</b>');

						$contents = array ('form' => draw_form('campaigns', FILENAME_CAMPAIGNS, 'action=insert', 'post', 'enctype="multipart/form-data"'));
						$contents[] = array ('text' => TEXT_NEW_INTRO);
						$contents[] = array ('text' => '<br />'.TEXT_CAMPAIGNS_NAME.'<br />'.draw_input_field('campaigns_name'));
						$contents[] = array ('text' => '<br />'.TEXT_CAMPAIGNS_REFID.'<br />'.draw_input_field('campaigns_refID'));
						$contents[] = array ('align' => 'center', 'text' => '<br />'.button(BUTTON_SAVE).'&nbsp;'.button_link(BUTTON_CANCEL, href_link(FILENAME_CAMPAIGNS, 'page='.$_GET['page'].'&cID='.$_GET['cID'])));
						break;

					case 'edit' :
						$heading[] = array ('text' => '<b>'.TEXT_HEADING_EDIT_CAMPAIGN.'</b>');

						$contents = array ('form' => draw_form('campaigns', FILENAME_CAMPAIGNS, 'page='.$_GET['page'].'&cID='.$cInfo->campaigns_id.'&action=save', 'post', 'enctype="multipart/form-data"'));
						$contents[] = array ('text' => TEXT_EDIT_INTRO);
						$contents[] = array ('text' => '<br />'.TEXT_CAMPAIGNS_NAME.'<br />'.draw_input_field('campaigns_name', $cInfo->campaigns_name));
						$contents[] = array ('text' => '<br />'.TEXT_CAMPAIGNS_REFID.'<br />'.draw_input_field('campaigns_refID', $cInfo->campaigns_refID));
						$contents[] = array ('align' => 'center', 'text' => '<br />'.button(BUTTON_SAVE).'&nbsp;'.button_link(BUTTON_CANCEL, href_link(FILENAME_CAMPAIGNS, 'page='.$_GET['page'].'&cID='.$cInfo->campaigns_id)));
						break;

					case 'delete' :
						$heading[] = array ('text' => '<b>'.TEXT_HEADING_DELETE_CAMPAIGN.'</b>');

						$contents = array ('form' => draw_form('campaigns', FILENAME_CAMPAIGNS, 'page='.$_GET['page'].'&cID='.$cInfo->campaigns_id.'&action=deleteconfirm'));
						$contents[] = array ('text' => TEXT_DELETE_INTRO);
						$contents[] = array ('text' => '<br /><b>'.$cInfo->campaigns_name.'</b>');

						if ($cInfo->refferers_count > 0) {
							$contents[] = array ('text' => '<br />'.draw_checkbox_field('delete_refferers').' '.TEXT_DELETE_REFFERERS);
							$contents[] = array ('text' => '<br />'.sprintf(TEXT_DELETE_WARNING_REFFERERS, $cInfo->refferers_count));
						}

						$contents[] = array ('align' => 'center', 'text' => '<br />'.button(BUTTON_DELETE).'&nbsp;'.button_link(BUTTON_CANCEL, href_link(FILENAME_CAMPAIGNS, 'page='.$_GET['page'].'&cID='.$cInfo->campaigns_id)));
						break;

					default :
						if (is_object($cInfo)) {
							$heading[] = array ('text' => '<b>'.$cInfo->campaigns_name.'</b>');

							$contents[] = array ('align' => 'center', 'text' => button_link(BUTTON_EDIT, href_link(FILENAME_CAMPAIGNS, 'page='.$_GET['page'].'&cID='.$cInfo->campaigns_id.'&action=edit')).'&nbsp;'.button_link(BUTTON_DELETE, href_link(FILENAME_CAMPAIGNS, 'page='.$_GET['page'].'&cID='.$cInfo->campaigns_id.'&action=delete')));
							$contents[] = array ('text' => '<br />'.TEXT_DATE_ADDED.' '.date_short($cInfo->date_added));
							if (not_null($cInfo->last_modified))
								$contents[] = array ('text' => TEXT_LAST_MODIFIED.' '.date_short($cInfo->last_modified));
							$contents[] = array ('text' => TEXT_REFERER.'?refID='.$cInfo->campaigns_refID);
						}
						break;
				}

				if ((not_null($heading)) && (not_null($contents))) {
					echo '            <td width="25%" class="border" valign="top">'."\n";

					$box = new box;
					echo $box->infoBox($heading, $contents);

					echo '            </td>'."\n";
				}
				?>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</div>
<?php require(DIR_WS_INCLUDES.'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES.'application_bottom.php'); ?>